<?

JCAT_Package::ImportClass('JCAT_Controller',JCAT::PACKAGE_MVC) ;

class DataVerifierSetting extends JCAT_Controller
{
	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$aParent	JCAT_IController		拥有此视图的对象
	 * @param	$aDoc		UICtrlDocBase			主文档
	 * @return	void
	 */
	public function DataVerifierSetting(JCAT_IController $aParent,UICtrlDocBase $aDoc)
	{
		$this->JCAT_Controller(__CLASS__, $aParent) ;

		// 文档
		$this->AddDocument($aDoc,'MainDoc') ;
		
		// 主视图
		$aSubView = new DataVerifierSettingView($this) ;
		$aSubView->SetDocument($aDoc) ;
		$this->AddView($aSubView) ;
	}
	
	
	/**
	 * what's this
	 * 
	 * @access	public
	 * @return	void
	 */
	public function MainRun()
	{
		$aView = $this->GetView('DataVerifierSettingView') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'DataVerifierSettingView');
		
		$aView->LoadDataVerifier() ;
	}
	
	/**
	 * 
	 *
	 * @access	public
	 * @return	void
	 */
	public function AddDataVerifier($sClassName)
	{
		JCAT_ASSERT::ASSERT_IMPLEMENTS($sClassName,'IToolboxDataVerifierController',true,JCAT_Language::Sentence('校验器扩展(类:%s)必须实现 IToolboxDataVerifierController 接口；可能是安装了有故障的扩展，请尝试卸载故障扩展。',$sClassName)) ;
		
		$aDataVerifier = new DataVerifier($sClassName) ;
		$aDVDoc = $aDataVerifier->MainRun() ;
		
		// 用户取消
		if(!$aDVDoc)
		{
			return ;
		}

		JCAT_ASSERT::ASSERT_INSTANCE($aDVDoc,'IToolboxDataVerifierDoc') ;
		
		$aUICtrlDoc = $this->GetDocument('MainDoc') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlDoc,'UICtrlDocBase') ;

		// 加入新文档
		$aUICtrlDoc->AddDataVerifierDoc($aDVDoc) ;

		// 更新视图
		$aView = $this->GetView('DataVerifierSettingView') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'DataVerifierSettingView') ;

		$aView->LoadDataVerifier($aUICtrlDoc) ;
	}


	/**
	 * what's this
	 * 
	 * @access	public
	 * @param	$aDVDoc		IToolboxDataVerifierDoc
	 * @return	void
	 */
	public function ToggledDVEnable( IToolboxDataVerifierDoc $aDVDoc )
	{
		// old value
		$bOldValue = $aDVDoc->IsEnable() ;
		
		// 更新 DV文档 数据
		$aDVDoc->SetEnable(!$bOldValue) ;
		
		// 更新 UICtrl 文档状态
		$aUICtrlDoc = $this->GetDocument('MainDoc') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlDoc,'UICtrlDocBase') ;
		
		$aUICtrlDoc->SetChanged(true) ;
	}
	
	/**
	 * 
	 *
	 * @access	public
	 * @return	void
	 */
	public function ModifyDataVerifier( IToolboxDataVerifierDoc $aDVDoc )
	{		
		// UICtrl 文档
		$aUICtrlDoc = $this->GetDocument('MainDoc') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlDoc,'UICtrlDocBase') ;
				
		// 数据校验  控制器 类名
		$sControllerClassName = $aDVDoc->GetControllerName() ;
		JCAT_ASSERT::ASSERT_IMPLEMENTS($sControllerClassName,'IToolboxDataVerifierController',true,JCAT_Language::Sentence('校验器扩展(类:%s)必须实现 IToolboxDataVerifierController 接口；可能是安装了有故障的扩展，请尝试卸载故障扩展。',$sControllerClassName)) ;
		
		$aDataVerifier = new DataVerifier($sControllerClassName,$aDVDoc) ;
		
		// 用户取消
		if( !$aDataVerifier->MainRun() )
		{
			return ;
		}

		// 更新视图
		else
		{
			$aView = $this->GetView('DataVerifierSettingView') ;
			JCAT_ASSERT::ASSERT_INSTANCE($aView,'DataVerifierSettingView') ;
			
			$aView->LoadDataVerifier($aUICtrlDoc) ;
		}
	}
	
	/**
	 * 
	 *
	 * @access	public
	 * @return	void
	 */
	public function RemoveDataVerifier( IToolboxDataVerifierDoc $aDVDoc )
	{
		// UICtrl 文档
		$aUICtrlDoc = $this->GetDocument('MainDoc') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aUICtrlDoc,'UICtrlDocBase') ;
		
		// 移除
		$aUICtrlDoc->RemoveDataVerifierDoc($aDVDoc) ;
		
		// 更新视图
		$aView = $this->GetView('DataVerifierSettingView') ;
		JCAT_ASSERT::ASSERT_INSTANCE($aView,'DataVerifierSettingView') ;
			
		$aView->LoadDataVerifier($aUICtrlDoc) ;
	}
}

?>